package net.lab1024.sa.admin.module.business.yct.yctTeeth.service;

import java.util.HashMap;
import java.util.List;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.dao.UserDao;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.entity.UserEntity;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.form.UserAddForm;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.form.UserQueryForm;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.form.UserUpdateForm;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.vo.SendTemplateMessageItemVo;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.vo.TemplateMessageVo;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.vo.UserVO;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.manager.DialogueManager;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.manager.YctTeethHospitalManager;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 小程序用戶 Service
 *
 * @Author zhangben
 * @Date 2024-10-10 13:24:57
 * @Copyright 20241218
 */

@Service
public class UserService {

    @Resource
    private UserDao userDao;

    @Resource
    private DialogueManager dialogueManager;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<UserVO> queryPage(UserQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<UserVO> list = userDao.queryPage(page, queryForm);
        PageResult<UserVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(UserAddForm addForm) {
        UserEntity userEntity = SmartBeanUtil.copy(addForm, UserEntity.class);
        userDao.insert(userEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(UserUpdateForm updateForm) {
        UserEntity userEntity = SmartBeanUtil.copy(updateForm, UserEntity.class);
        userDao.updateById(userEntity);
        return ResponseDTO.ok();
    }

    public List<UserVO> queryKf(UserQueryForm queryForm) {

        return userDao.queryKf(queryForm);
    }

    public List<UserVO> queryUser(UserQueryForm queryForm) {
        return userDao.queryUser(queryForm);
    }

    public Boolean testSendMsg() {
        HashMap<String, String> temMap =  new HashMap<>();
        temMap.put("time2","2016-01-12");
        temMap.put("short_thing3","消息1测试");
        temMap.put("character_string1","123");

        TemplateMessageVo programTemplateMessageVo = new TemplateMessageVo();
        programTemplateMessageVo.setTemplate_id("hOeGsduunDuB2DyiCMP8dfuurjkBEpMMHZMqNqFZvmU");

        //组装关键字数据
        HashMap<String, SendTemplateMessageItemVo> hashMap = new HashMap<>();
        temMap.forEach((key, value) -> hashMap.put(key, new SendTemplateMessageItemVo(value)));
        programTemplateMessageVo.setPage("pages/index/index?familyId=5");
        programTemplateMessageVo.setData(hashMap);
        programTemplateMessageVo.setTouser("o0ZIW7aRPNL9DGns4O-yEm1GqclU");
        return dialogueManager.sendMiniSubscribeMessage(programTemplateMessageVo);
    }

    public List<UserVO> queryKfMessage() {
      return  userDao.queryKfMessage();
    }
}
